package com.rpframework.website.device.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.rpframework.core.BaseService;
import com.rpframework.utils.Pager;
import com.rpframework.website.device.dao.IGoodsProStockRecordDao;
import com.rpframework.website.device.domain.Category;
import com.rpframework.website.device.domain.GoodsPro;
import com.rpframework.website.device.domain.GoodsProStockRecord;



@Service
public class GoodsProStockRecordService extends BaseService{
	public @Resource IGoodsProStockRecordDao iDao;
	
	@Resource GoodsProService goodsProService;
	
	
	public Pager<GoodsProStockRecord> getPager(Pager<GoodsProStockRecord> pager) {
		long startTime = System.currentTimeMillis();
		List<GoodsProStockRecord> list = iDao.doPager(this.packageMyBatisParam(pager));
		pager.setItemList(list);
		pager.setCostTime(System.currentTimeMillis() - startTime);
		return pager;
	}
	
	/**
	 * 商品记录入库
	 * @param t
	 * @return
	 */
	public boolean doSave(GoodsProStockRecord t) {
	
		Integer stock=iDao.searchStock(t.getGoodsProId(), t.getUserId());
		if(stock==null){stock=0;}
				if(t.getAmount()+stock>0){
					return iDao.insert(t);
				}
				return false;
		
	}
	
	public Integer getTotalProductType(Integer userId){
		return iDao.getTotalProductType(userId);
		
	}
	

	
	public Pager<GoodsProStockRecord> searchRecordByTime(Pager<GoodsProStockRecord> pager) {
		long startTime = System.currentTimeMillis();
		List<GoodsProStockRecord> list = iDao.doByTimePager(this.packageMyBatisParam(pager));
		pager.setItemList(list);
		pager.setCostTime(System.currentTimeMillis() - startTime);
		return pager;
	}

	public Pager<GoodsProStockRecord> searchInRecordByTime(Pager<GoodsProStockRecord> pager) {
		long startTime = System.currentTimeMillis();
		List<GoodsProStockRecord> list = iDao.searchRecordInStockByTimePager(this.packageMyBatisParam(pager));
		pager.setItemList(list);
		pager.setCostTime(System.currentTimeMillis() - startTime);
		return pager;
	}

	public Pager<GoodsProStockRecord> searchOutRecordByTime(Pager<GoodsProStockRecord> pager) {
		long startTime = System.currentTimeMillis();
		List<GoodsProStockRecord> list = iDao.searchRecordOutStockByTimePager(this.packageMyBatisParam(pager));
		pager.setItemList(list);
		pager.setCostTime(System.currentTimeMillis() - startTime);
		return pager;
	}
	
	
	
	
	

	


	

	
	
	
}
